/*
 * This file is part of Super Luigi Bros.
 * Super Luigi Bros is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Super Luigi Bros is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Super Luigi Bros.  If not, see <http://www.gnu.org/licenses/>.
 */

package luigibros.logic;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "luigi_type")
@XmlEnum
public enum DirectionType 
{
	 @XmlEnumValue("open_ground")
     DEFAULT(0),
     @XmlEnumValue("open_jump")
     OPENJUMP(1),
     @XmlEnumValue("closed_left_ground")
     CLOSEDLEFTGROUND(2),
     @XmlEnumValue("closed_right_ground")
     CLOSEDRIGHTGROUND(3),
	 @XmlEnumValue("closed_left_jump")
     CLOSEDLEFTJUMP(4),
     @XmlEnumValue("closed_right_jump")
     CLOSEDRIGHTJUMP(5),
     @XmlEnumValue("closed_full_jump")
     CLOSEDFULLJUMP(6),
     @XmlEnumValue("crouch")
     CROUCH(7);
     
     private byte situation;

     private static final Map<Byte, DirectionType> map;
     static {
                     map = new HashMap<Byte, DirectionType>();
                     DirectionType[] list = values();
                     for(DirectionType type : list)
                             map.put(new Byte(type.toByte()), type);
     }
     
     //attributes of a situation
     private boolean canLeft;
     private boolean canRight;
     private boolean canJump;
     private boolean canFall;
     
     private DirectionType (int situation){
             this.situation = (byte) situation;
             switch(situation)
             {
             case 0:        canLeft		= true;
             				canRight	= true;
             				canJump		= true;
             				canFall		= false;
             				break;
             case 1:		canLeft		= true;
             				canRight 	= true;
             				canJump		= false;
             				canFall		= true;
             				break;         				
             case 2:        canLeft		= false;
             				canRight	= true;
             				canJump		= true;
             				canFall		= false;
             				break;
             case 3:        canLeft 	= true;
             				canRight	= false;
             				canJump		= true;
             				canFall		= false;
             				break;
             case 4:        canLeft		= false;
             				canRight	= true;
             				canJump		= false;
             				canFall		= true;
             				break;
             case 5:		canLeft		= true;
             				canRight	= false;
             				canJump		= false;
             				canFall		= true;
             				break;
             case 6:		canLeft		= false;
             				canRight	= false;
             				canJump		= false;
             				canFall		= true;
             				break;
             case 7:		canLeft		= false;
             				canRight	= false;
             				canJump		= true;
             				canFall		= false;        	 			
             }
     }
     
     public byte	toByte()						{return situation;}
     public boolean canMoveLeft()                   {return canLeft;}
     public boolean canMoveRight()                  {return canRight;}
     public boolean canJump()                       {return canJump;}
     public boolean canFall()						{return canFall;}
     public String getState()                       {return this.toString() + ".toString()";}
}